#include "com_call.h"

#include <stdio.h>
#include <string.h>


void test_p2s(char* str, char* str2) {
    printf("p1=%s, p2=%s\n", str, str2);
}
void test_p1v() {
    printf("%s no params.\n", __FUNCTION__);
}

int get_int(int i) {
    return i + 100;
}

char* get_append_str(char* src) {
    static char sbuf[256] = {0};
    memset(sbuf, 0, sizeof(sbuf));
    if(strlen(src) + strlen("hello-><-world.\n") + 1 <= sizeof(sbuf)) {
        sprintf(sbuf, "hello->%s<-world.", src);
        return sbuf;
    }
    return "overflowed!";
}

void test_257_params(char* p1, char* p2, char* p3, char* p4, char* p5, char* p6,
        char* p7, char* p8, char* p9, char* p10, char* p11, char* p12,
        char* p13, char* p14, char* p15, char* p16, char* p17, char* p18,
        char* p19, char* p20, char* p21, char* p22, char* p23, char* p24,
        char* p25, char* p26, char* p27, char* p28, char* p29, char* p30,
        char* p31, char* p32, char* p33, char* p34, char* p35, char* p36,
        char* p37, char* p38, char* p39, char* p40, char* p41, char* p42,
        char* p43, char* p44, char* p45, char* p46, char* p47, char* p48,
        char* p49, char* p50, char* p51, char* p52, char* p53, char* p54,
        char* p55, char* p56, char* p57, char* p58, char* p59, char* p60,
        char* p61, char* p62, char* p63, char* p64, char* p65, char* p66,
        char* p67, char* p68, char* p69, char* p70, char* p71, char* p72,
        char* p73, char* p74, char* p75, char* p76, char* p77, char* p78,
        char* p79, char* p80, char* p81, char* p82, char* p83, char* p84,
        char* p85, char* p86, char* p87, char* p88, char* p89, char* p90,
        char* p91, char* p92, char* p93, char* p94, char* p95, char* p96,
        char* p97, char* p98, char* p99, char* p100, char* p101, char* p102,
        char* p103, char* p104, char* p105, char* p106, char* p107, char* p108,
        char* p109, char* p110, char* p111, char* p112, char* p113, char* p114,
        char* p115, char* p116, char* p117, char* p118, char* p119, char* p120,
        char* p121, char* p122, char* p123, char* p124, char* p125, char* p126,
        char* p127, char* p128, char* p129, char* p130, char* p131, char* p132,
        char* p133, char* p134, char* p135, char* p136, char* p137, char* p138,
        char* p139, char* p140, char* p141, char* p142, char* p143, char* p144,
        char* p145, char* p146, char* p147, char* p148, char* p149, char* p150,
        char* p151, char* p152, char* p153, char* p154, char* p155, char* p156,
        char* p157, char* p158, char* p159, char* p160, char* p161, char* p162,
        char* p163, char* p164, char* p165, char* p166, char* p167, char* p168,
        char* p169, char* p170, char* p171, char* p172, char* p173, char* p174,
        char* p175, char* p176, char* p177, char* p178, char* p179, char* p180,
        char* p181, char* p182, char* p183, char* p184, char* p185, char* p186,
        char* p187, char* p188, char* p189, char* p190, char* p191, char* p192,
        char* p193, char* p194, char* p195, char* p196, char* p197, char* p198,
        char* p199, char* p200, char* p201, char* p202, char* p203, char* p204,
        char* p205, char* p206, char* p207, char* p208, char* p209, char* p210,
        char* p211, char* p212, char* p213, char* p214, char* p215, char* p216,
        char* p217, char* p218, char* p219, char* p220, char* p221, char* p222,
        char* p223, char* p224, char* p225, char* p226, char* p227, char* p228,
        char* p229, char* p230, char* p231, char* p232, char* p233, char* p234,
        char* p235, char* p236, char* p237, char* p238, char* p239, char* p240,
        char* p241, char* p242, char* p243, char* p244, char* p245, char* p246,
        char* p247, char* p248, char* p249, char* p250, char* p251, char* p252,
        char* p253, char* p254, char* p255, char* p256, char* p257) {
    printf("arg1=%s\n", p1);
    printf("arg2=%s\n", p2);
    printf("arg3=%s\n", p3);
    printf("arg4=%s\n", p4);
    printf("arg5=%s\n", p5);
    printf("arg6=%s\n", p6);
    printf("arg7=%s\n", p7);
    printf("arg8=%s\n", p8);
    printf("arg9=%s\n", p9);
    printf("arg10=%s\n", p10);
    printf("arg11=%s\n", p11);
    printf("arg12=%s\n", p12);
    printf("arg13=%s\n", p13);
    printf("arg14=%s\n", p14);
    printf("arg15=%s\n", p15);
    printf("arg16=%s\n", p16);
    printf("arg17=%s\n", p17);
    printf("arg18=%s\n", p18);
    printf("arg19=%s\n", p19);
    printf("arg20=%s\n", p20);
    printf("arg21=%s\n", p21);
    printf("arg22=%s\n", p22);
    printf("arg23=%s\n", p23);
    printf("arg24=%s\n", p24);
    printf("arg25=%s\n", p25);
    printf("arg26=%s\n", p26);
    printf("arg27=%s\n", p27);
    printf("arg28=%s\n", p28);
    printf("arg29=%s\n", p29);
    printf("arg30=%s\n", p30);
    printf("arg31=%s\n", p31);
    printf("arg32=%s\n", p32);
    printf("arg33=%s\n", p33);
    printf("arg34=%s\n", p34);
    printf("arg35=%s\n", p35);
    printf("arg36=%s\n", p36);
    printf("arg37=%s\n", p37);
    printf("arg38=%s\n", p38);
    printf("arg39=%s\n", p39);
    printf("arg40=%s\n", p40);
    printf("arg41=%s\n", p41);
    printf("arg42=%s\n", p42);
    printf("arg43=%s\n", p43);
    printf("arg44=%s\n", p44);
    printf("arg45=%s\n", p45);
    printf("arg46=%s\n", p46);
    printf("arg47=%s\n", p47);
    printf("arg48=%s\n", p48);
    printf("arg49=%s\n", p49);
    printf("arg50=%s\n", p50);
    printf("arg51=%s\n", p51);
    printf("arg52=%s\n", p52);
    printf("arg53=%s\n", p53);
    printf("arg54=%s\n", p54);
    printf("arg55=%s\n", p55);
    printf("arg56=%s\n", p56);
    printf("arg57=%s\n", p57);
    printf("arg58=%s\n", p58);
    printf("arg59=%s\n", p59);
    printf("arg60=%s\n", p60);
    printf("arg61=%s\n", p61);
    printf("arg62=%s\n", p62);
    printf("arg63=%s\n", p63);
    printf("arg64=%s\n", p64);
    printf("arg65=%s\n", p65);
    printf("arg66=%s\n", p66);
    printf("arg67=%s\n", p67);
    printf("arg68=%s\n", p68);
    printf("arg69=%s\n", p69);
    printf("arg70=%s\n", p70);
    printf("arg71=%s\n", p71);
    printf("arg72=%s\n", p72);
    printf("arg73=%s\n", p73);
    printf("arg74=%s\n", p74);
    printf("arg75=%s\n", p75);
    printf("arg76=%s\n", p76);
    printf("arg77=%s\n", p77);
    printf("arg78=%s\n", p78);
    printf("arg79=%s\n", p79);
    printf("arg80=%s\n", p80);
    printf("arg81=%s\n", p81);
    printf("arg82=%s\n", p82);
    printf("arg83=%s\n", p83);
    printf("arg84=%s\n", p84);
    printf("arg85=%s\n", p85);
    printf("arg86=%s\n", p86);
    printf("arg87=%s\n", p87);
    printf("arg88=%s\n", p88);
    printf("arg89=%s\n", p89);
    printf("arg90=%s\n", p90);
    printf("arg91=%s\n", p91);
    printf("arg92=%s\n", p92);
    printf("arg93=%s\n", p93);
    printf("arg94=%s\n", p94);
    printf("arg95=%s\n", p95);
    printf("arg96=%s\n", p96);
    printf("arg97=%s\n", p97);
    printf("arg98=%s\n", p98);
    printf("arg99=%s\n", p99);
    printf("arg100=%s\n", p100);
    printf("arg101=%s\n", p101);
    printf("arg102=%s\n", p102);
    printf("arg103=%s\n", p103);
    printf("arg104=%s\n", p104);
    printf("arg105=%s\n", p105);
    printf("arg106=%s\n", p106);
    printf("arg107=%s\n", p107);
    printf("arg108=%s\n", p108);
    printf("arg109=%s\n", p109);
    printf("arg110=%s\n", p110);
    printf("arg111=%s\n", p111);
    printf("arg112=%s\n", p112);
    printf("arg113=%s\n", p113);
    printf("arg114=%s\n", p114);
    printf("arg115=%s\n", p115);
    printf("arg116=%s\n", p116);
    printf("arg117=%s\n", p117);
    printf("arg118=%s\n", p118);
    printf("arg119=%s\n", p119);
    printf("arg120=%s\n", p120);
    printf("arg121=%s\n", p121);
    printf("arg122=%s\n", p122);
    printf("arg123=%s\n", p123);
    printf("arg124=%s\n", p124);
    printf("arg125=%s\n", p125);
    printf("arg126=%s\n", p126);
    printf("arg127=%s\n", p127);
    printf("arg128=%s\n", p128);
    printf("arg129=%s\n", p129);
    printf("arg130=%s\n", p130);
    printf("arg131=%s\n", p131);
    printf("arg132=%s\n", p132);
    printf("arg133=%s\n", p133);
    printf("arg134=%s\n", p134);
    printf("arg135=%s\n", p135);
    printf("arg136=%s\n", p136);
    printf("arg137=%s\n", p137);
    printf("arg138=%s\n", p138);
    printf("arg139=%s\n", p139);
    printf("arg140=%s\n", p140);
    printf("arg141=%s\n", p141);
    printf("arg142=%s\n", p142);
    printf("arg143=%s\n", p143);
    printf("arg144=%s\n", p144);
    printf("arg145=%s\n", p145);
    printf("arg146=%s\n", p146);
    printf("arg147=%s\n", p147);
    printf("arg148=%s\n", p148);
    printf("arg149=%s\n", p149);
    printf("arg150=%s\n", p150);
    printf("arg151=%s\n", p151);
    printf("arg152=%s\n", p152);
    printf("arg153=%s\n", p153);
    printf("arg154=%s\n", p154);
    printf("arg155=%s\n", p155);
    printf("arg156=%s\n", p156);
    printf("arg157=%s\n", p157);
    printf("arg158=%s\n", p158);
    printf("arg159=%s\n", p159);
    printf("arg160=%s\n", p160);
    printf("arg161=%s\n", p161);
    printf("arg162=%s\n", p162);
    printf("arg163=%s\n", p163);
    printf("arg164=%s\n", p164);
    printf("arg165=%s\n", p165);
    printf("arg166=%s\n", p166);
    printf("arg167=%s\n", p167);
    printf("arg168=%s\n", p168);
    printf("arg169=%s\n", p169);
    printf("arg170=%s\n", p170);
    printf("arg171=%s\n", p171);
    printf("arg172=%s\n", p172);
    printf("arg173=%s\n", p173);
    printf("arg174=%s\n", p174);
    printf("arg175=%s\n", p175);
    printf("arg176=%s\n", p176);
    printf("arg177=%s\n", p177);
    printf("arg178=%s\n", p178);
    printf("arg179=%s\n", p179);
    printf("arg180=%s\n", p180);
    printf("arg181=%s\n", p181);
    printf("arg182=%s\n", p182);
    printf("arg183=%s\n", p183);
    printf("arg184=%s\n", p184);
    printf("arg185=%s\n", p185);
    printf("arg186=%s\n", p186);
    printf("arg187=%s\n", p187);
    printf("arg188=%s\n", p188);
    printf("arg189=%s\n", p189);
    printf("arg190=%s\n", p190);
    printf("arg191=%s\n", p191);
    printf("arg192=%s\n", p192);
    printf("arg193=%s\n", p193);
    printf("arg194=%s\n", p194);
    printf("arg195=%s\n", p195);
    printf("arg196=%s\n", p196);
    printf("arg197=%s\n", p197);
    printf("arg198=%s\n", p198);
    printf("arg199=%s\n", p199);
    printf("arg200=%s\n", p200);
    printf("arg201=%s\n", p201);
    printf("arg202=%s\n", p202);
    printf("arg203=%s\n", p203);
    printf("arg204=%s\n", p204);
    printf("arg205=%s\n", p205);
    printf("arg206=%s\n", p206);
    printf("arg207=%s\n", p207);
    printf("arg208=%s\n", p208);
    printf("arg209=%s\n", p209);
    printf("arg210=%s\n", p210);
    printf("arg211=%s\n", p211);
    printf("arg212=%s\n", p212);
    printf("arg213=%s\n", p213);
    printf("arg214=%s\n", p214);
    printf("arg215=%s\n", p215);
    printf("arg216=%s\n", p216);
    printf("arg217=%s\n", p217);
    printf("arg218=%s\n", p218);
    printf("arg219=%s\n", p219);
    printf("arg220=%s\n", p220);
    printf("arg221=%s\n", p221);
    printf("arg222=%s\n", p222);
    printf("arg223=%s\n", p223);
    printf("arg224=%s\n", p224);
    printf("arg225=%s\n", p225);
    printf("arg226=%s\n", p226);
    printf("arg227=%s\n", p227);
    printf("arg228=%s\n", p228);
    printf("arg229=%s\n", p229);
    printf("arg230=%s\n", p230);
    printf("arg231=%s\n", p231);
    printf("arg232=%s\n", p232);
    printf("arg233=%s\n", p233);
    printf("arg234=%s\n", p234);
    printf("arg235=%s\n", p235);
    printf("arg236=%s\n", p236);
    printf("arg237=%s\n", p237);
    printf("arg238=%s\n", p238);
    printf("arg239=%s\n", p239);
    printf("arg240=%s\n", p240);
    printf("arg241=%s\n", p241);
    printf("arg242=%s\n", p242);
    printf("arg243=%s\n", p243);
    printf("arg244=%s\n", p244);
    printf("arg245=%s\n", p245);
    printf("arg246=%s\n", p246);
    printf("arg247=%s\n", p247);
    printf("arg248=%s\n", p248);
    printf("arg249=%s\n", p249);
    printf("arg250=%s\n", p250);
    printf("arg251=%s\n", p251);
    printf("arg252=%s\n", p252);
    printf("arg253=%s\n", p253);
    printf("arg254=%s\n", p254);
    printf("arg255=%s\n", p255);
    printf("arg256=%s\n", p256);
    printf("arg257=%s\n", p257);

    printf("\ndone!\n\n");
}

int main() {
    PARAM_INFO my_call = {0};

    {
        my_call.param_cnt = 0;
        my_call.params_addr = 0;
        my_call.fn = test_p1v;
        com_call(&my_call);
    }

    {
        char* str = "hello myWrold!";
        char* str2 = "Lucy";
        void* params[2] = {str, str2};
        my_call.param_cnt = sizeof(params) / sizeof(params[0]);
        my_call.params_addr = params;
        my_call.fn = (pF)test_p2s;
        com_call(&my_call);
    }


    {
        void* params[1] = {(void*)2};
        int i_ret = 0;

        my_call.param_cnt = sizeof(params) / sizeof(params[0]);
        my_call.params_addr = params;
        my_call.fn = (pF)get_int;
        i_ret = (int)com_call(&my_call);
        printf("i_ret=%d\n", i_ret);
    }

    {
        char* s_ret = NULL;
        void* params[1] = {"Linux"};
        my_call.param_cnt = sizeof(params) / sizeof(params[0]);
        my_call.params_addr = params;
        my_call.fn = (pF)get_append_str;
        s_ret = (char*)com_call(&my_call);
        printf("s_ret=%s\n", s_ret);
    }

    {
        void* params[257] = {0};
        char buf[257][8] = {0};
        int i = 0;

        for(; i < 257; ++i) {
            sprintf(buf[i], "p%d", i);
            params[i] = buf[i];
        }

        my_call.param_cnt = sizeof(params) / sizeof(params[0]);
        my_call.params_addr = params;
        my_call.fn = (pF)test_257_params;
        com_call(&my_call);
    }

    return 0;
}
